// WndPlayer.cpp : implementation file
//

#include "stdafx.h"
#include "BBViewer.h"
#include "WndPlayer.h"


// CWndPlayer

IMPLEMENT_DYNAMIC(CWndPlayer, CWnd)

CWndPlayer::CWndPlayer()
{
}

CWndPlayer::~CWndPlayer()
{
}


BEGIN_MESSAGE_MAP(CWndPlayer, CWnd)
	ON_MESSAGE(WM_CTL_MESSAGE, OnCtlMessage)
	ON_WM_PAINT()
	ON_WM_CREATE()
	ON_WM_SIZE()
END_MESSAGE_MAP()



// CWndPlayer message handlers


int CWndPlayer::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	int i;
	LPST_BMP_INFO lpBmpInfo;
	for (i=0;i<4;i++)
	{
		lpBmpInfo = theApp.BmpInfo.GetAt(biPlayForward_normal+i);
		m_btnPlay.SetBitmaps(i, lpBmpInfo->hbmpImage);

		lpBmpInfo = theApp.BmpInfo.GetAt(biPause_normal+i);
		m_btnPause.SetBitmaps(i, lpBmpInfo->hbmpImage);

		lpBmpInfo = theApp.BmpInfo.GetAt(biPlayBackward_normal+i);
		m_btnBackPlay.SetBitmaps(i, lpBmpInfo->hbmpImage);

		lpBmpInfo = theApp.BmpInfo.GetAt(biStop_normal+i);
		m_btnStop.SetBitmaps(i, lpBmpInfo->hbmpImage);

		lpBmpInfo = theApp.BmpInfo.GetAt(biStepForward_normal+i);
		m_btnStepNext.SetBitmaps(i, lpBmpInfo->hbmpImage);

		lpBmpInfo = theApp.BmpInfo.GetAt(biStepBackward_normal+i);
		m_btnStepPrev.SetBitmaps(i, lpBmpInfo->hbmpImage);

		lpBmpInfo = theApp.BmpInfo.GetAt(biStepForward_k_normal+i);
		m_btnStepNextKF.SetBitmaps(i, lpBmpInfo->hbmpImage);

		lpBmpInfo = theApp.BmpInfo.GetAt(biStepBackward_k_normal+i);
		m_btnStepPrevKF.SetBitmaps(i, lpBmpInfo->hbmpImage);

		lpBmpInfo = theApp.BmpInfo.GetAt(biNextFile_normal+i);
		m_btnNextFile.SetBitmaps(i, lpBmpInfo->hbmpImage);

		lpBmpInfo = theApp.BmpInfo.GetAt(biPrevFile_normal+i);
		m_btnPrevFile.SetBitmaps(i, lpBmpInfo->hbmpImage);

	}

	LPST_WND_POS lpWndPos = theApp.WndPos.GetAt(wpPlaybackCtrl);
	m_nMode = lpWndPos->nMode;

	int nBtnCount = 0;
	CCtrlButton *pBtn[10];

	pBtn[nBtnCount++] = &m_btnPlay;
	pBtn[nBtnCount++] = &m_btnPause;
	pBtn[nBtnCount++] = &m_btnBackPlay;
	pBtn[nBtnCount++] = &m_btnStop;
	pBtn[nBtnCount++] = &m_btnStepNext;
	pBtn[nBtnCount++] = &m_btnStepPrev;
	pBtn[nBtnCount++] = &m_btnStepNextKF;
	pBtn[nBtnCount++] = &m_btnStepPrevKF;
	pBtn[nBtnCount++] = &m_btnNextFile;
	pBtn[nBtnCount++] = &m_btnPrevFile;

	for (i=0;i<nBtnCount;i++)
	{
		lpBmpInfo = theApp.BmpInfo.GetAt(biPlayForward_normal+(i*4));
		if (!pBtn[i]->Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0,0,0,0), this, lpBmpInfo->uImageID, NULL))
			return -1;
	}

	SetPlayStatus(FALSE);
	LoadText();

	m_ToolTipCtrl.Create(this);
	m_ToolTipCtrl.Activate(TRUE);

	for (i=0;i<nBtnCount;i++)
		m_ToolTipCtrl.AddTool(pBtn[i], m_sarrText.GetAt(i));

#if (_STEP_FORWARD_ACTION == _MOVE_FRAME)
	m_btnStepNextKF.ShowWindow(SW_HIDE);
#else
	m_btnStepNext.ShowWindow(SW_HIDE);
#endif

	return 0;
}

void CWndPlayer::OnPaint()
{
	CPaintDC dc(this); // device context for painting
	// TODO: Add your message handler code here
	// Do not call CWnd::OnPaint() for painting messages

}

void CWndPlayer::OnSize(UINT nType, int cx, int cy)
{
	CWnd::OnSize(nType, cx, cy);

	LPST_WND_POS lpWndPos;
	lpWndPos = theApp.WndPos.GetAt(wpPB_playFwd);
	theApp.SetWindowPosition(&m_btnPlay, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo);
	lpWndPos = theApp.WndPos.GetAt(wpPB_playBwd);
	theApp.SetWindowPosition(&m_btnBackPlay, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo);
	lpWndPos = theApp.WndPos.GetAt(wpPB_StepFwd);
	theApp.SetWindowPosition(&m_btnStepNext, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo);
	lpWndPos = theApp.WndPos.GetAt(wpPB_StepBwd);
	theApp.SetWindowPosition(&m_btnStepPrev, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo);
	lpWndPos = theApp.WndPos.GetAt(wpPB_StepFwd_k);
	theApp.SetWindowPosition(&m_btnStepNextKF, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo);
	lpWndPos = theApp.WndPos.GetAt(wpPB_StepBwd_k);
	theApp.SetWindowPosition(&m_btnStepPrevKF, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo);
	lpWndPos = theApp.WndPos.GetAt(wpPB_Pause);
	theApp.SetWindowPosition(&m_btnPause, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo);
	lpWndPos = theApp.WndPos.GetAt(wpPB_Stop);
	theApp.SetWindowPosition(&m_btnStop, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo);
	lpWndPos = theApp.WndPos.GetAt(wpPB_NextFile);
	theApp.SetWindowPosition(&m_btnNextFile, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo);
	lpWndPos = theApp.WndPos.GetAt(wpPB_PrevFile);
	theApp.SetWindowPosition(&m_btnPrevFile, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo);

}

BOOL CWndPlayer::PreTranslateMessage(MSG* pMsg)
{
	m_ToolTipCtrl.RelayEvent(pMsg);
	return CWnd::PreTranslateMessage(pMsg);
}

long CWndPlayer::OnCtlMessage(UINT wParam, LONG lParam)
{
	CWnd* pParent = GetParent();
	pParent->PostMessage(WM_PLB_MESSAGE, wParam, lParam);
	return 0;
}

void CWndPlayer::SetPlayStatus(BOOL bPlay)
{
	if (m_nMode == 1)
	{
		if (bPlay)
		{
			m_btnPlay.ShowWindow(SW_HIDE);
			m_btnPause.ShowWindow(SW_SHOW);
		}
		else
		{
			m_btnPlay.ShowWindow(SW_SHOW);
			m_btnPause.ShowWindow(SW_HIDE);
		}
	}
}

void CWndPlayer::RefreshLang()
{
	LoadText();

	int i;
	int nBtnCount = 0;
	CCtrlButton *pBtn[10];
	pBtn[nBtnCount++] = &m_btnPlay;
	pBtn[nBtnCount++] = &m_btnPause;
	pBtn[nBtnCount++] = &m_btnBackPlay;
	pBtn[nBtnCount++] = &m_btnStop;
	pBtn[nBtnCount++] = &m_btnStepNext;
	pBtn[nBtnCount++] = &m_btnStepPrev;
	pBtn[nBtnCount++] = &m_btnStepNextKF;
	pBtn[nBtnCount++] = &m_btnStepPrevKF;
	pBtn[nBtnCount++] = &m_btnNextFile;
	pBtn[nBtnCount++] = &m_btnPrevFile;

	for (i=0;i<nBtnCount;i++)
	{
		m_ToolTipCtrl.DelTool(pBtn[i]);
		m_ToolTipCtrl.AddTool(pBtn[i], m_sarrText.GetAt(i));
	}
}

void CWndPlayer::LoadText()
{
	m_sarrText.RemoveAll();

	m_sarrText.Add(theApp.GetUIString(APPNAME_BUTTON, KEYNAME_BUTTON_PLAY_FW, KEYNAME_BUTTON_PLAY_FW));
	m_sarrText.Add(theApp.GetUIString(APPNAME_BUTTON, KEYNAME_BUTTON_PAUSE, KEYNAME_BUTTON_PAUSE));
	m_sarrText.Add(theApp.GetUIString(APPNAME_BUTTON, KEYNAME_BUTTON_PLAY_BW, KEYNAME_BUTTON_PLAY_BW));
	m_sarrText.Add(theApp.GetUIString(APPNAME_BUTTON, KEYNAME_BUTTON_STOP, KEYNAME_BUTTON_STOP));
	m_sarrText.Add(theApp.GetUIString(APPNAME_BUTTON, KEYNAME_BUTTON_STEP_FW, KEYNAME_BUTTON_STEP_FW));
	m_sarrText.Add(theApp.GetUIString(APPNAME_BUTTON, KEYNAME_BUTTON_STEP_BW, KEYNAME_BUTTON_STEP_BW));
	m_sarrText.Add(theApp.GetUIString(APPNAME_BUTTON, KEYNAME_BUTTON_STEP_FW_K, KEYNAME_BUTTON_STEP_FW_K));
	m_sarrText.Add(theApp.GetUIString(APPNAME_BUTTON, KEYNAME_BUTTON_STEP_BW_K, KEYNAME_BUTTON_STEP_BW_K));
	m_sarrText.Add(theApp.GetUIString(APPNAME_BUTTON, KEYNAME_BUTTON_NEXT_FILE, KEYNAME_BUTTON_NEXT_FILE));
	m_sarrText.Add(theApp.GetUIString(APPNAME_BUTTON, KEYNAME_BUTTON_PREV_FILE, KEYNAME_BUTTON_PREV_FILE));
}